using UnityEngine;


namespace HEFramework
{
    /// <summary>
    ///
    /// UI滑动视图物体行为基类
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2024-07-24 17:11:49
    /// ----------------------------------------
    /// </summary>
    [RequireComponent(typeof(RectTransform))]
    public class UIScrollViewItemBehaviourBase : MonoBehaviour, IUIScrollViewItemBehaviour
    {
        private UIScrollViewBehaviourBase parent;
        private GameObject self;
        private RectTransform rectTransform;
        private int currentRow;

        public UIScrollViewBehaviourBase Parent => parent;

        public GameObject GameObject
        {
            get
            {
                if (self == null)
                {
                    self = this.gameObject;
                }

                return self;
            }
        }

        public RectTransform RectTransform
        {
            get
            {
                if (rectTransform == null)
                {
                    rectTransform = self.GetComponent<RectTransform>();
                }

                return rectTransform;
            }
        }

        public int CurrentRow => currentRow;


        public void Awake()
        {
            self = gameObject;
            rectTransform = self.GetComponent<RectTransform>();
        }

        public Transform GetTransform()
        {
            return self.transform;
        }

        public GameObject GetGameObject()
        {
            return self.gameObject;
        }

        public void Assign(UIScrollViewBehaviourBase _v, int _row)
        {
            parent = _v;
            currentRow = _row;
        }
    }
}